﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Hostal.Bussines.Entities;
using Hostal.Bussines.Repository.Service;

namespace Hostal.Bussines.Repository
{
    public class HuespedRepository:MasterRepository,IHuespedRepository
    {

        public List<Huesped> GetAllFromHuesped()
        {
            var query = from h in Context.Huesped
                            select h;
            return query.ToList();
        }

        public Huesped GetFromHuespedById(int id)
        {
            return Context.Huesped.Find(id);
        }

        public List<Huesped> GetFromHuespedByDni(string dni)
        {
            var query = from h in Context.Huesped
                            select h;
            if (dni != null && dni != "")
            {
                query = from h in query
                        where h.DNI.ToUpper().Contains(dni.ToUpper())
                        select h;
            }
            return query.ToList();
        }

        public void AddHuesped(Huesped huesped)
        {
            Context.Huesped.Add(huesped);
            Context.SaveChanges();
        }

        public void UpdateHuesped(Huesped huesped)
        {
            Context.Entry(huesped).State= System.Data.EntityState.Modified;
            Context.SaveChanges();
        }

        public void RemoveHuesped(int id)
        {
            var existe = Context.Huesped
                .Where(h =>h.IdHuesped.Equals(id)).SingleOrDefault();
            if (existe != null)
            {
                Context.Huesped.Remove(existe);
                Context.SaveChanges();
            }
        }
    }
}
